<%@page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/jsp/comm_css_include.jsp"%>

<!doctype html>
<html>
<head>
	<style>
		.marginTop20{
			margin-top: 20px;
		}
	</style>
</head>
<body class="gray-bg">
<div class="container creditbody">
			<input type="hidden" id="busiId"/>
     		<input type="hidden" id="cusId"/>
     		<input type="hidden" id="cusNo"/>
	 <div class="iboxtitle">
	 	<span><i class="glyphicon glyphicon-map-marker"></i>&nbsp;&nbsp;贷后业务&nbsp;&gt;&nbsp;逾期风控&nbsp;&gt;&nbsp;销账处理</span>
     </div>
     <div class="ibox-content ibox-con">
     	 <form class="form-horizontal" id="credit-info">
        	 <div class="tche-padding">
          		<table cellpadding="0" cellspacing="0" border="0" class="buyinfor-table" >
					<tr>	
						<td align="right">
							<label class="control-label np">结算日期：</label>
						</td>
						<td>
							<input id="dateClearing" name="dateClearing"  class="laydate-icon form-control">
						</td>
					</tr>
					
					<tr>	
						<td align="right">
							<label class="control-label np">逾期金额：</label>
						</td>
						<td>
							<input type="text" id="amount_overdue" name="amountOverdue" placeholder="请输入逾期金额" onkeyup="value=value.replace(/[^\-?\d.]/g,'')" class="form-control">
						</td>
					</tr>
					
					<tr>	
						<td align="right">
							<label class="control-label np">还款账号：</label>
						</td>
						<td>
							<input type="text" placeholder="请输入还款卡号" id="cardnoRepayment" name="cardnoRepayment" onKeyUp="this.value=this.value.replace(/[^\.\d]/g,'');this.value=this.value.replace('.','');" class="form-control">
							
						</td>
						<td valign="bottom" align="left">
							&nbsp;<button class="btn dpbtn_green" type="button" onclick="query();">检测卡号</button>
							&nbsp;<button type="button" class="btn dpbtn_blue" onclick="chargeOffs();">确认销账</button>
						</td>
					</tr>
				</table>
				<div class="name-hidden" >
					<span class="xzname" id="xzname"></span>
				</div>
			</div>
		</form>				
     </div>
</div>
	
	<!-- public quote -->
    <%@include file="/jsp/comm_js_include.jsp"%>
     <script src="${basePath}/js/plugins/layer/laydate/laydate.js"></script>
    <!-- custom js -->
    
    <script type="text/javascript">
    
    jQuery(function($) { 
    	laydate({
	        elem: '#dateClearing', 
	        event: 'focus' 
	    });
    });
	//销账
	var chargeOffs=function(){
		var amountOverdue=$("#amount_overdue").val();
		var cusId=$("#cusId").val();
		var busiId=$("#busiId").val();
		var cardnoRepayment=$("#cardnoRepayment").val();
		var dateClearing=$("#dateClearing").val();
		if(cardnoRepayment=="" ||amountOverdue=="" || dateClearing==""){
			layer.msg("请仔细检查是否有未填写的值！", {icon: 5});
			return;
		}
		if(!amountOverdue.match(/^(:?(:?\d+.\d+)|(:?\d+))$/)){
			layer.msg("请输入正确的逾期金额！", {icon: 5});
			return;
		}
		
		if(isFlag==false){
			layer.msg("数据不存在或者已经被删除,无法销账！", {icon: 5});
			return;
		}
		var data={
				"cusId":cusId,
				"busiId":busiId,
				"amountOverdue":amountOverdue,
				"cardnoRepayment":cardnoRepayment,
				"dateClearing":dateClearing
		};
		layer.confirm('您确认要销账吗？', {
			  btn: ['确定','取消'] //按钮
		},function(){
			layer.closeAll();
			$.dpAjax({
	    		url:'${basePath}/DhOverdueChargeOffsController/save',
	    		data:data,
					success: function(datas){
	    			  if(datas.flag == "100100")
					  {
	    				  layer.msg('执行成功！', {icon: 6});
						  return;
					  }
					  if(datas.flag == "100200")
	                  {
						  $.fn.showDatas({"datas":datas});
	                	  return;
	                  }
	            }
	    	});
		});	
	}
	var isFlag=true;
  	 //搜索
	var query = function(){
    	var cardnoRepayment=$("#cardnoRepayment").val();
    	if(cardnoRepayment==null || $.trim(cardnoRepayment)==""){
    		layer.msg("请填写查询的还款卡号信息！", {icon: 5});
   	   		return;
    	}
    	var data={};
    	data.cardnoRefund=cardnoRepayment;
    	 $.dpAjax({
	    		url:'${basePath}/DhOverdueChargeOffsController/queryCusInfo',
	    		data:data,
   				success: function(datas){
	    			  if(datas.flag == "100100")
					  {	
	    				  if(datas.result!=null){
	    					  $("#busiId").val(datas.result.busiId);
		    				  $("#cusId").val(datas.result.cusId);
		    				  $(".name-hidden").show();
		    				  $("#xzname").html("归属客户："+datas.result.name);
		    				  isFlag=true;
		    				  return;
	    				  }
						  return;
					  }
					  if(datas.flag == "100200")
	                  {
						  $.fn.showDatas({"datas":datas});
						  isFlag=false;
	                	  return;
	                  }
					  if(datas.flag == "100300")
					  {
    					  $(".name-hidden").show();
    					  $("#xzname").html("数据不存在或者已经被删除");
    					  isFlag=false;
    					  return;
    				  }
                }
	    	});
    }
    </script>
</body>
</html>
